package com.zhihaoliang.coroutine.buss.home

import android.content.ComponentName
import android.content.Intent
import androidx.recyclerview.widget.LinearLayoutManager
import com.zhihaoliang.coroutine.base.BaseActivity
import com.zhihaoliang.coroutine.buss.caltimeout.CancelTimeoutActivity
import com.zhihaoliang.coroutine.buss.channel.ChannelActivity
import com.zhihaoliang.coroutine.buss.concurrent.ConcurrentActivity
import com.zhihaoliang.coroutine.buss.dispatcher.DispatcherActivity
import com.zhihaoliang.coroutine.buss.excep.ExceptionActivity
import com.zhihaoliang.coroutine.buss.flow.FlowActivity
import com.zhihaoliang.coroutine.buss.net.ui.NetActivity
import com.zhihaoliang.coroutine.buss.suspend.SuspendFunctionActivity
import com.zhihaoliang.coroutine.databinding.HomeActivityBinding
import com.zhihaoliang.coroutine.util.log

/**
 * @author 支豪亮
 * @date 2022/10/20 10:32
 * @des
 */
class HomeActivity : BaseActivity<HomeActivityBinding>() {

    val list = listOf(HomeBean("网络操作", NetActivity::class.java.name),
                      HomeBean("取消和超时", CancelTimeoutActivity::class.java.name),
                      HomeBean("suspend function 方法介绍", SuspendFunctionActivity::class.java.name),
                      HomeBean("协成调度器", DispatcherActivity::class.java.name),
                      HomeBean("流的操作", FlowActivity::class.java.name),
                      HomeBean("Channel 通道介绍", ChannelActivity::class.java.name),
                      HomeBean("异常处理", ExceptionActivity::class.java.name),
                      HomeBean("并行", ConcurrentActivity::class.java.name))

    override fun initDataBinding(): HomeActivityBinding =
        HomeActivityBinding.inflate(layoutInflater)

    override fun initView() {
        super.initView()
        val linearLayoutManager = LinearLayoutManager(this)
        linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
        dataBinding.rcyHome.layoutManager = linearLayoutManager
        dataBinding.rcyHome.adapter = HomeAdapter(list) {
            log(it.clazzPath)
            val intent = Intent()
            intent.component = ComponentName(this@HomeActivity, it.clazzPath)
            startActivity(intent)
        }
    }
}